#include <iostream>
#include <vector>
#include <cstdlib>
#include <cstdio>
struct Serializable {
	virtual std :: string serialize() = 0;
	virtual Serializable* deserialize(const std::string& obj) = 0;
};

struct A : public Serializable {
	
	void foo() {
		std::cout << 5 << std::endl;
	}
	
	Serializable* deserialize(const std::string& obj) {
		if(obj[0] == 'A') {
			a = atoi(obj.substr(1).c_str());
			a_objects.push_back(this);
			return this;
		} 
		return 0;
	}
	std :: string serialize() { 
		std :: string result = "A";
		char a_val[100];
		sprintf(a_val, "%d" ,a);
		result += std :: string(a_val);
		return result;
	}
	static std::vector<A*> a_objects;
	
	private:
		int a;
};



class B : public Serializable {
	int b;
	public :
		void bar() {
			std::cout << 6 << std::endl;
		}
		Serializable* deserialize(const std::string& obj) {
			if(obj[0] == 'B') {
				b = atoi(obj.substr(1).c_str());
				b_objects.push_back(this);
				return this;
			} 
			return 0;
		}
		std :: string serialize() { 
			std :: string result = "B";
			char b_val[100];
			sprintf(b_val, "%d", b);
			result += std :: string(b_val);
			return result;
		}
	
	static std::vector<B*> b_objects;
};

struct Consumer {
	virtual void consume() = 0;
};

struct ConsumerA  : public Consumer{
	void consume() {
		for(int i = 0; i < A::a_objects.size(); i++) {				
			A::a_objects[i]->foo();
			A::a_objects.erase(A::a_objects.begin() + i);
		}
	}
};

struct ConsumerB : public Consumer {
	void consume() {
		for(int i = 0; i < B::b_objects.size(); i++) {				
			B::b_objects[i]->bar();
			B::b_objects.erase(B::b_objects.begin() + i);
		}
	}
};
